home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / ui_lists.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  8.5 KB  |  334 lines

  1. /*****************************************************************************
  2.   FILE           : ui_lists.c
  3.   SHORTNAME      : lists.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : build and manage lists for choosing f-types, io-types,
  7.                    outFunction, actFunction, site and siteFunction
  8.   NOTES          :
  9.  
  10.   AUTHOR         : Tilman Sommer
  11.   DATE           : 27.8.1990
  12.  
  13.   CHANGED BY     :
  14.   IDENTIFICATION : @(#)ui_lists.c    1.14 4/7/94
  15.   SCCS VERSION   : 1.14
  16.   LAST CHANGE    : 4/7/94
  17.  
  18.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  19.              
  20. ******************************************************************************/
  21.  
  22.  
  23. #include <stdio.h>
  24.  
  25. #include "ui.h"
  26.  
  27. #include <X11/Xaw/List.h>
  28.  
  29. #include "glob_typ.h"    /*  Kernel constant and type definitions  */
  30. #include "kr_ui.h"    /*  Kernel interface functions    */
  31.  
  32. #include "ui_textP.h"
  33. #include "ui_utilP.h"
  34. #include "ui_xWidgets.h"
  35. #include "ui_infoP.h"
  36. #include "ui_mainP.h"
  37. #include "ui_info.h"
  38.  
  39. #include "ui_lists.ph"
  40.  
  41.  
  42. /*****************************************************************************
  43.   FUNCTION : ui_list_getFirstItem
  44.  
  45.   PURPOSE  : return the first list item of the given type
  46.   RETURNS  : char *
  47.   NOTES    :
  48.  
  49.   UPDATE   : 27.8.1990
  50. ******************************************************************************/
  51.  
  52. static char *ui_list_getFirstItem(int type)
  53.  
  54. {
  55.     char *name, *funcName;
  56.     int  funcType;
  57.     int  i, funcNo;
  58.     Bool found = FALSE;
  59.  
  60.     switch (type) {
  61.       case UI_LIST_FTYPE_ACT_FUNC:
  62.     type = UI_LIST_ACT_FUNC;
  63.     break;
  64.       case UI_LIST_FTYPE_OUT_FUNC:
  65.     type = UI_LIST_OUT_FUNC;
  66.     break;
  67.     }    
  68.  
  69.     switch (type) {
  70.       case UI_LIST_ACT_FUNC:
  71.       case UI_LIST_OUT_FUNC:
  72.       case UI_LIST_SITE_FUNC:
  73.       case UI_LIST_LEARN_FUNC:
  74.       case UI_LIST_UPDATE_FUNC:
  75.       case UI_LIST_INIT_FUNC:
  76.     ui_list_noOfFunctions = 0;
  77.     for (i=1; (i <= krui_getNoOfFunctions()) AND (NOT found); i++) {
  78.         krui_getFuncInfo(i,&funcName, &funcType);
  79.         if (found = (type == funcType)) funcNo = i;
  80.     }
  81.     if (found) {
  82.         ui_list_noOfFunctions = 1;
  83.         ui_list_currentFuncNo[funcType] = funcNo;
  84.         return(funcName); 
  85.     } else return("*** no function present ***");
  86.     break;
  87.       case UI_LIST_FTYPE_NAME:
  88.       case UI_LIST_FTYPE:
  89.     ui_list_noOfFtypes = 0;
  90.     if (krui_setFirstFTypeEntry()) {
  91.         ui_list_noOfFtypes++;
  92.         return(krui_getFTypeName());
  93.     } else
  94.         return("*** no f-types present ***");
  95.     break;
  96.       case UI_LIST_IOTYPE:
  97.     ui_list_currentIOType = 1;
  98.     return(ui_list_iotypes[ui_list_currentIOType]);
  99.     break;
  100.       case UI_LIST_SITE:
  101.     ui_list_noOfSites = 0;
  102.     if (krui_getFirstSiteTableEntry(&name, &funcName)) {
  103.         ui_list_noOfSites++;
  104.         return(name);
  105.     } else
  106.         return("*** no sites ***");
  107.     break;
  108.       case UI_LIST_FTYPE_SITE:
  109.     ui_list_noOfFTypeSites = 0;
  110.     if (krui_setFirstFTypeSite()) {
  111.         ui_list_noOfFTypeSites++;
  112.         return((char *) krui_getFTypeSiteName());
  113.     } else
  114.         return("*** no sites ***");
  115.     break;
  116.       case UI_LIST_UNIT_SITE:
  117.     ui_list_noOfSites = 0;
  118.     if (krui_setFirstSite()) {
  119.         ui_list_noOfSites++;
  120.         return((char *) krui_getSiteName());
  121.     } else
  122.         return("*** no sites ***");
  123.     break;
  124.     }
  125.     return(NULL);
  126. }
  127.  
  128.  
  129. /*****************************************************************************
  130.   FUNCTION : ui_list_getNextItem
  131.  
  132.   PURPOSE  : return the next list item of the given type
  133.   RETURNS  : char *
  134.   NOTES    :
  135.  
  136.   UPDATE   : 27.8.1990
  137. ******************************************************************************/
  138.  
  139. static char *ui_list_getNextItem(int type)
  140.  
  141. {
  142.     char *name, *funcName;
  143.     int  funcType;
  144.     int  i, funcNo;
  145.     Bool found = FALSE;
  146.  
  147.     switch (type) {
  148.       case UI_LIST_FTYPE_ACT_FUNC:
  149.     type = UI_LIST_ACT_FUNC;
  150.     break;
  151.       case UI_LIST_FTYPE_OUT_FUNC:
  152.     type = UI_LIST_OUT_FUNC;
  153.     break;
  154.     }    
  155.  
  156.     switch (type) {
  157.       case UI_LIST_ACT_FUNC:
  158.       case UI_LIST_OUT_FUNC:
  159.       case UI_LIST_SITE_FUNC:
  160.       case UI_LIST_LEARN_FUNC:
  161.       case UI_LIST_UPDATE_FUNC:
  162.       case UI_LIST_INIT_FUNC:
  163.     for (i = ui_list_currentFuncNo[type] + 1; 
  164.          (i <= krui_getNoOfFunctions()) AND NOT found ; i++) {
  165.         krui_getFuncInfo(i,&funcName, &funcType);
  166.         if (found = (type == funcType)) funcNo = i;
  167.     }
  168.     if (found) {
  169.         ui_list_noOfFunctions++;
  170.         ui_list_currentFuncNo[funcType] = funcNo;
  171.         return(funcName); 
  172.     } else return(NULL);
  173.     break;
  174.       case UI_LIST_FTYPE_NAME:
  175.       case UI_LIST_FTYPE:
  176.     if (krui_setNextFTypeEntry())
  177.         return(krui_getFTypeName());
  178.     else
  179.         return(NULL);
  180.     break;
  181.       case UI_LIST_IOTYPE:
  182.     if (ui_list_currentIOType < 11)
  183.         return(ui_list_iotypes[++ui_list_currentIOType]);
  184.     else return(NULL);
  185.     break;
  186.       case UI_LIST_SITE:
  187.     if (krui_getNextSiteTableEntry(&name, &funcName)) {
  188.         ui_list_noOfSites++;
  189.         return(name);
  190.     } else
  191.         return(NULL);
  192.     break;
  193.       case UI_LIST_FTYPE_SITE:
  194.     if (krui_setNextFTypeSite()) {
  195.         ui_list_noOfFTypeSites++;
  196.         return((char *) krui_getFTypeSiteName());
  197.     } else
  198.         return(NULL);
  199.     break;
  200.       case UI_LIST_UNIT_SITE:
  201.     if (krui_setNextSite()) {
  202.         ui_list_noOfSites++;
  203.         return((char *) krui_getSiteName());
  204.     } else
  205.         return(NULL);
  206.     break;
  207.     }
  208.     return(NULL);
  209. }
  210.  
  211.  
  212. /*****************************************************************************
  213.   FUNCTION : ui_list_buildList
  214.  
  215.   PURPOSE  : buikd and display the list described in the list descriptor
  216.   RETURNS  : void
  217.   NOTES    :
  218.  
  219.   UPDATE   : 27.8.1990
  220. ******************************************************************************/
  221.  
  222. void ui_list_buildList(struct SimpleListType *listDescriptorPtr)
  223.  
  224. {
  225.     char *string;
  226.  
  227.  
  228.     listDescriptorPtr->noOfItems = 0;
  229.  
  230.     string = ui_list_getFirstItem(listDescriptorPtr->listType);
  231.  
  232.     while (string != NULL) {
  233.     ui_xAddListEntry(listDescriptorPtr, string);
  234.     string = ui_list_getNextItem(listDescriptorPtr->listType);
  235.     }
  236. }
  237.  
  238.  
  239. /*****************************************************************************
  240.   FUNCTION : ui_list_setValue
  241.  
  242.   PURPOSE  : callback. Called when a list item was choosed. 
  243.   RETURNS  : void
  244.   NOTES    :
  245.  
  246.   UPDATE   : 28.8.1990
  247. ******************************************************************************/
  248.  
  249. void ui_list_setUnitValue(Widget w, struct SimpleListType *listDescrPtr, 
  250.     XawListReturnStruct *listStructPtr)
  251.  
  252. {
  253.     char  buf[120];
  254.  
  255.     ui_list_returnIndex = listStructPtr->list_index;
  256.  
  257.     /* if no item selected then return */
  258.     if (listStructPtr->list_index == XAW_LIST_NONE)
  259.     return;
  260.  
  261.     /* an item is selected */
  262.     /* but if no ftypes present when requesting f-types then return */
  263.     if (((listDescrPtr->listType == UI_LIST_FTYPE) OR
  264.      (listDescrPtr->listType == UI_LIST_FTYPE_NAME)) AND 
  265.     (ui_list_noOfFtypes == 0))
  266.     return;
  267.     
  268.     switch (listDescrPtr->listType) {
  269.       case UI_LIST_IOTYPE:
  270.     listDescrPtr->unitPtr->iotype = (listStructPtr->list_index + 1);
  271.     break;
  272.       case UI_LIST_FTYPE:
  273.     sprintf(listDescrPtr->unitPtr->ftype, "%s", listStructPtr->string);
  274.     break;
  275.       case UI_LIST_ACT_FUNC:
  276.     sprintf(listDescrPtr->unitPtr->actFuncName, "%s", 
  277.         listStructPtr->string);
  278.     break;
  279.       case UI_LIST_OUT_FUNC:
  280.     sprintf(listDescrPtr->unitPtr->outFuncName, "%s", 
  281.         listStructPtr->string);
  282.     break;
  283.       case UI_LIST_FTYPE_ACT_FUNC:
  284.       case UI_LIST_FTYPE_OUT_FUNC:
  285.       case UI_LIST_FTYPE_NAME:
  286.       case UI_LIST_SITE_FUNC:
  287.       case UI_LIST_SITE:
  288.       case UI_LIST_UNIT_SITE:
  289.     /* site functions are requested only during editing sites!
  290.        Thus this must be handled in a different way. */
  291.     sprintf(ui_list_returnName, "%s", listStructPtr->string);
  292.     break;
  293.       case UI_LIST_LEARN_FUNC:
  294.     ui_checkError(krui_setLearnFunc(listStructPtr->string));
  295.     sprintf(buf,"Learning func:  %s\n",listStructPtr->string);
  296.     ui_tw_printMessage(buf); 
  297.     ui_xSetLabel(ui_remoteMessageWidget, buf);
  298.     break;
  299.       case UI_LIST_UPDATE_FUNC:
  300.     ui_checkError(krui_setUpdateFunc(listStructPtr->string)); 
  301.     sprintf(buf,"Update func  :  %s\n",listStructPtr->string);
  302.     ui_tw_printMessage(buf);
  303.     ui_xSetLabel(ui_remoteMessageWidget, buf);
  304.     break;
  305.       case UI_LIST_INIT_FUNC:
  306.     ui_checkError(krui_setInitialisationFunc(listStructPtr->string));
  307.     sprintf(buf,"Init. func   :  %s\n",listStructPtr->string);
  308.     ui_tw_printMessage(buf);
  309.     ui_xSetLabel(ui_remoteMessageWidget, buf);
  310.     break;
  311.     } 
  312.     /* unitPtr may be NULL as well ! */
  313.     if (listDescrPtr->unitPtr == &ui_targetUnit)
  314.     {
  315.     ui_info_getDisplayedUnitAttributes(&ui_targetWidgets, &ui_targetUnit);
  316.         ui_info_setUnitItems(ui_targetWidgets, ui_targetUnit);
  317.     }
  318.     else {
  319.     if (listDescrPtr->unitPtr == &ui_sourceUnit)
  320.     {
  321.         ui_info_getDisplayedUnitAttributes(&ui_sourceWidgets, 
  322.                            &ui_sourceUnit);
  323.         ui_info_setUnitItems(ui_sourceWidgets, ui_sourceUnit);
  324.     }
  325.     } 
  326.  
  327. }
  328.     
  329.  
  330.  
  331.  
  332. /* end of file */
  333. /* lines: 350 */
  334.